﻿using System;
using System.Collections.Generic;
using System.Linq;

using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.DataAccess.SqlDatabase;

namespace Fuse8.ContentManagementFramework.DataAccess.SqlAccess.Mappers
{
    public class CmsBaseSqlEntityDataMapper<TEntity, TKey> : BaseSqlEntityDataMapper<TEntity, TKey>
        where TEntity : class, IEntityObject<TKey>, new()
        where TKey : IComparable<TKey>, IEquatable<TKey>
    {
        public CmsBaseSqlEntityDataMapper()
            : base()
        { }

        public CmsBaseSqlEntityDataMapper(IList<string> ignoreToProperties)
            : this(ignoreToProperties, null)
        { }

        public CmsBaseSqlEntityDataMapper(IList<string> ignoreToProperties, IList<string> ignoreFromProperties)
            : base(ignoreToProperties, ignoreFromProperties)
        {
            if (ignoreToProperties == null)
            {
                ignoreToProperties = new List<string>();
            }
            else
            {
                ignoreToProperties = ignoreToProperties.ToList();
            }

            ignoreToProperties.Add("EntityMetaInformation");

            foreach (var item in ignoreToProperties)
            {
                SqlMap.WithIgnoreTo(item);
            }

            if (ignoreFromProperties != null)
            {
                foreach (var item in ignoreFromProperties)
                {
                    SqlMap.WithIgnoreFrom(item);
                }
            }
        }
    }
}
